package com.jinzecloud.fiction.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.query.MPJLambdaQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.jinzecloud.fiction.bean.TbCatalogue;
import com.jinzecloud.fiction.service.TbBookNameService;
import com.jinzecloud.fiction.service.TbCatalogueService;
import com.jinzecloud.fiction.utils.PageUtils;
import com.jinzecloud.fiction.utils.Query;
import com.jinzecloud.fiction.vo.TbBookContentVo;
import com.jinzecloud.fiction.vo.TbCatalogueVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.jinzecloud.fiction.mapper.TbBookContentMapper;
import com.jinzecloud.fiction.bean.TbBookContent;
import com.jinzecloud.fiction.service.TbBookContentService;


@Service("tbBookContentService")
public class TbBookContentServiceImpl extends ServiceImpl<TbBookContentMapper, TbBookContent> implements TbBookContentService {

    @Autowired
    private TbBookContentMapper tbBookContentMapper;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        MPJLambdaWrapper<TbBookContent> tbBookContentMPJLambdaQueryWrapper = new MPJLambdaWrapper<TbBookContent>()
                .selectAll(TbBookContent.class)
                .select(TbCatalogue::getCatCatalogueName)
                .leftJoin(TbCatalogue.class, TbCatalogue::getCatId,TbBookContent::getCoCatalogueId);
        IPage<TbBookContentVo> page=tbBookContentMapper.selectJoinPage(
                new Page<TbBookContentVo>(Long.parseLong((String) params.get("page")),Long.parseLong((String) params.get("limit"))),
                TbBookContentVo.class,
                tbBookContentMPJLambdaQueryWrapper
        );
        return new PageUtils(page);
    }

    @Override
    public void updateStatus(TbBookContent tbBookContent) {
        UpdateWrapper<TbBookContent> tbBookContentUpdateWrapper = new UpdateWrapper<>();
        tbBookContentUpdateWrapper.set("co_status",tbBookContent.getCoStatus())
                .eq("co_id",tbBookContent.getCoId());
        this.update(tbBookContentUpdateWrapper);
    }

}